<?php
class Ehl_Form_Recherche extends Jnd_Form
{
    protected $_type;

    public function init()
    {
        switch ($this->_type)
        {
            case 'adminteams':
                $this->traitementAdminTeams();
            break;
            case 'adminlocations':
                $this->traitementAdminLocations();
            break;
            case 'adminplayers':
                $this->traitementAdminPlayers();
            break;
            case 'admingames':
                $this->traitementAdminGames();
            break;
            case 'adminusers':
                $this->traitementAdminUsers();
            break;
            case 'adminnews':
                $this->traitementAdminNews();
            break;
            default:
        }
    
    }

    public function __construct( $listes, $type = 'devis', $options = null )
    {
        foreach ($listes as $listeType => $listeValeurs) {
            $this->setProperty($listeType, $listeValeurs);
        }
        $this->_type = $type;
        parent::__construct('Formulaire', $options);
        $this->setElementDecorators(array(
            "Formulaire"
        ), array(), false);
    }

    private function setProperty( $property, $value )
    {
        $this->$property = $value;
    }

    private function traitementAdminTeams()
    {
        // nom du formulaire
        $this->setName($this->_type);
        //
        $selection = new Zend_Form_Element_Select("SelectionMesTous");
        $selection->setAttribs(array(
            "onchange" => "actionSubmit('" . $this->_type . "', '/administration/teams/index/tout/' + $('#SelectionMesTous').val());"
        ));
        $selection->addMultiOptions(array(
            "0" => __("My teams"), 
            "1" => __("All teams")
        ));
        $this->addElement($selection);
        
        // team name
        $this->addElement('text', 'name', array(
            'attribs' => array(
                'maxlength' => 60, 
                'size' => 6
            )
        ));
        
        // create user
        $this->addElement('text', 'creationUser', array(
            'attribs' => array(
                'maxlength' => 255, 
                'size' => 4
            )
        ));
        
        // date creation
        $this->addElement('datepicker', 'creationDate', array(
            'attribs' => array(
                'maxlength' => 14, 
                'size' => 8, 
                'autocomplete' => 'off'
            )
        ));
    
    }

    private function traitementAdminPlayers()
    {
        // nom du formulaire
        $this->setName($this->_type);
        //
        $selection = new Zend_Form_Element_Select("SelectionMesTous");
        $selection->setAttribs(array(
            "onchange" => "actionSubmit('" . $this->_type . "', '/administration/players/index/tout/' + $('#SelectionMesTous').val());"
        ));
        $selection->addMultiOptions(array(
            "0" => __("My players"), 
            "1" => __("All players")
        ));
        $this->addElement($selection);
        
        // player lastname
        $this->addElement('text', 'lastname', array(
            'attribs' => array(
                'maxlength' => 60, 
                'size' => 6
            )
        ));
        
        // player firstname
        $this->addElement('text', 'firstname', array(
            'attribs' => array(
                'maxlength' => 60, 
                'size' => 6
            )
        ));
        
        // player nickname
        $this->addElement('text', 'nickname', array(
            'attribs' => array(
                'maxlength' => 60, 
                'size' => 6
            )
        ));
        
        // create user
        $this->addElement('text', 'creationUser', array(
            'attribs' => array(
                'maxlength' => 255, 
                'size' => 4
            )
        ));
        
        // date creation
        $this->addElement('datepicker', 'creationDate', array(
            'attribs' => array(
                'maxlength' => 14, 
                'size' => 8, 
                'autocomplete' => 'off'
            )
        ));
    
    }

    private function traitementAdminLocations()
    {
        // nom du formulaire
        $this->setName($this->_type);
        //
        $selection = new Zend_Form_Element_Select("SelectionMesTous");
        $selection->setAttribs(array(
            "onchange" => "actionSubmit('" . $this->_type . "', '/administration/locations/index/tout/' + $('#SelectionMesTous').val());"
        ));
        $selection->addMultiOptions(array(
            "0" => __("My locations"), 
            "1" => __("All locations")
        ));
        $this->addElement($selection);
        
        // team name
        $this->addElement('text', 'name', array(
            'attribs' => array(
                'maxlength' => 60, 
                'size' => 6
            )
        ));
        
        // create user
        $this->addElement('text', 'creationUser', array(
            'attribs' => array(
                'maxlength' => 255, 
                'size' => 4
            )
        ));
        
        // date creation
        $this->addElement('datepicker', 'creationDate', array(
            'attribs' => array(
                'maxlength' => 14, 
                'size' => 8, 
                'autocomplete' => 'off'
            )
        ));
    
    }

    private function traitementAdminGames()
    {
        // nom du formulaire
        $this->setName($this->_type);
        //
        $selection = new Zend_Form_Element_Select("SelectionMesTous");
        $selection->setAttribs(array(
            "onchange" => "actionSubmit('" . $this->_type . "', '/administration/games/index/tout/' + $('#SelectionMesTous').val());"
        ));
        $selection->addMultiOptions(array(
            "0" => __("My games"), 
            "1" => __("All games")
        ));
        $this->addElement($selection);
        
        $team = new Administration_Model_Teams();
        $teams = $team->listerPourSelect("name", true);
        
        // team home
        $this->addElement('select', 'idteamhome', array(
            'attribs' => array(
                'maxlength' => 60, 
                'options' => $teams
            )
        ));
        
        // team visitor
        $this->addElement('select', 'idteamvisitor', array(
            'attribs' => array(
                'maxlength' => 60, 
                'options' => $teams
            )
        ));
        
        // create user
        $this->addElement('text', 'creationUser', array(
            'attribs' => array(
                'maxlength' => 255, 
                'size' => 4
            )
        ));
        
        // date creation
        $this->addElement('datepicker', 'creationDate', array(
            'attribs' => array(
                'maxlength' => 14, 
                'size' => 8, 
                'autocomplete' => 'off'
            )
        ));
    
    }

    private function traitementAdminUsers()
    {
        // nom du formulaire
        $this->setName($this->_type);
        //
        $selection = new Zend_Form_Element_Select("SelectionMesTous");
        $selection->setAttribs(array(
            "onchange" => "actionSubmit('" . $this->_type . "', '/administration/users/index/tout/' + $('#SelectionMesTous').val());"
        ));
        $selection->addMultiOptions(array(
            "0" => __("My users"), 
            "1" => __("All users")
        ));
        $this->addElement($selection);
        
        $team = new Administration_Model_Teams();
        $teams = $team->listerPourSelect("name", true);
        
        // create user
        $this->addElement('text', 'creationUser', array(
            'attribs' => array(
                'maxlength' => 255, 
                'size' => 4
            )
        ));
        
        // date creation
        $this->addElement('datepicker', 'creationDate', array(
            'attribs' => array(
                'maxlength' => 14, 
                'size' => 8, 
                'autocomplete' => 'off'
            )
        ));
    
    }

    private function traitementAdminNews()
    {
        // nom du formulaire
        $this->setName($this->_type);
        //
        $selection = new Zend_Form_Element_Select("SelectionMesTous");
        $selection->setAttribs(array(
            "onchange" => "actionSubmit('" . $this->_type . "', '/administration/news/index/tout/' + $('#SelectionMesTous').val());"
        ));
        $selection->addMultiOptions(array(
            "0" => __("My news"), 
            "1" => __("All news")
        ));
        $this->addElement($selection);
        
        // news title
        $this->addElement('text', 'title', array(
            'attribs' => array(
                'maxlength' => 60, 
                'size' => 6
            )
        ));
        
        // news message
        $this->addElement('text', 'message', array(
            'attribs' => array(
                'maxlength' => 60, 
                'size' => 6
            )
        ));
        
        // create user
        $this->addElement('text', 'creationUser', array(
            'attribs' => array(
                'maxlength' => 255, 
                'size' => 4
            )
        ));
        
        // date creation
        $this->addElement('datepicker', 'creationDate', array(
            'attribs' => array(
                'maxlength' => 14, 
                'size' => 8, 
                'autocomplete' => 'off'
            )
        ));
    
    }
}